package pub.cleangao;

import java.math.BigDecimal;
import java.util.*;



public class Main2 {

    public static void main(String[] args) throws Exception {

        Map<String, BigDecimal> oriMap = ReadFinance.readOriginalFromSheet("E:/998_temp_run/original.xlsx");
        Map<String, BigDecimal> sysMap = ReadFinance.readFinanceFromSheet("E:/998_temp_run/finance.xlsx");

        Set<String> oriExist = new HashSet<>();
        for (Map.Entry<String, BigDecimal> entry : oriMap.entrySet()) {
            String key = entry.getKey();
            if (key == null || key.equals("")) {
                continue;
            }
            if (sysMap.get(key) == null) {
                // 不存在这个订单号
            } else {
                // 存在此订单号
                BigDecimal sysVal = sysMap.get(key);
                BigDecimal oriVal = entry.getValue();
                if (sysVal.compareTo(oriVal) != 0) {
                    // 相同订单号，不同金额
                } else {
                    // 相同订单号，相同金额
                    oriExist.add(key);
                }
            }
        }// for

        Set<String> sysExist = new HashSet<>();
        for (Map.Entry<String, BigDecimal> entry : sysMap.entrySet()) {
            String key = entry.getKey();
            if (key == null || key.equals("")) {
                continue;
            }
            if (oriMap.get(key) == null) {
                // 不存在这个订单号

            } else {
                // 存在此订单号
                BigDecimal oriVal = oriMap.get(key);
                BigDecimal sysVal = entry.getValue();
                if (sysVal.compareTo(oriVal) != 0) {
                    // 相同订单号，不同金额
                } else {
                    // 相同订单号，相同金额
                    sysExist.add(key);
                }
            }
        }
        // 执行删除表操作
        System.out.println("Sys:" + sysExist.size() + ",Ori:" + oriExist.size());
        ReadFinance.deleteOriginalRow(oriExist, "E:/998_temp_run/original.xlsx");
        ReadFinance.deleteFinanceRow(sysExist, "E:/998_temp_run/finance.xlsx");


    }
}
